package com.outsourcing.bottle.db;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;

import com.outsourcing.bottle.domain.LanguageConfig;

/**
 * 
 * @author 06peng
 *
 */
public class LanguageConfigTable {

	private final String TABLE_BOTTLE_LANGUAGE_CONFIG = "bottle_language_config";
	
	private String bottle_throw_tips_en = "bottle_throw_tips_en";
	private String bottle_throw_tips_2_en ="bottle_throw_tips_2_en";
	private String bottle_gain_tips_en = "bottle_gain_tips_en";
	private String bottle_gain_tips_2_en = "bottle_gain_tips_2_en";
	private String exchange_profile_tip_en = "exchange_profile_tip_en";
	private String exchange_profile_tip_2_en = "exchange_profile_tip_2_en";
	private String exchange_profile_intro_en = "exchange_profile_intro_en";
	private String exchange_photo_tip_en = "exchange_photo_tip_en";
	private String exchange_photo_tip_2_en = "exchange_photo_tip_2_en";
	private String exchange_photo_intro_en = "exchange_photo_intro_en";
	private String without_btfriend_tip_en = "without_btfriend_tip_en";
	private String without_btfriend_tip_2_en = "without_btfriend_tip_2_en";
	private String without_friend_tip_en = "without_friend_tip_en";
	private String without_friend_tip_2_en = "without_friend_tip_2_en";
	private String without_maybeknow_tip_en = "without_maybeknow_tip_en";
	private String without_maybeknow_tip_invite_en = "without_maybeknow_tip_invite_en";
	private String without_maybeknow_tip_setup_en = "without_maybeknow_tip_setup_en";
	private String without_maybeknow_tip_mobile_en = "without_maybeknow_tip_mobile_en";
	
	private String bottle_throw_tips_cn = "bottle_throw_tips_cn";
	private String bottle_throw_tips_2_cn ="bottle_throw_tips_2_cn";
	private String bottle_gain_tips_cn = "bottle_gain_tips_cn";
	private String bottle_gain_tips_2_cn ="bottle_gain_tips_2_cn";
	private String exchange_profile_tip_cn = "exchange_profile_tip_cn";
	private String exchange_profile_tip_2_cn = "exchange_profile_tip_2_cn";
	private String exchange_profile_intro_cn ="exchange_profile_intro_cn";
	private String exchange_photo_tip_cn ="exchange_photo_tip_cn";
	private String exchange_photo_tip_2_cn = "exchange_photo_tip_2_cn";
	private String exchange_photo_intro_cn = "exchange_photo_intro_cn";
	private String without_btfriend_tip_cn ="without_btfriend_tip_cn";
	private String without_btfriend_tip_2_cn = "without_btfriend_tip_2_cn";
	private String without_friend_tip_cn = "without_friend_tip_cn";
	private String without_friend_tip_2_cn = "without_friend_tip_2_cn";
	private String without_maybeknow_tip_cn ="without_maybeknow_tip_cn";
	private String without_maybeknow_tip_invite_cn ="without_maybeknow_tip_invite_cn";
	private String without_maybeknow_tip_setup_cn ="without_maybeknow_tip_setup_cn";
	private String without_maybeknow_tip_mobile_cn = "without_maybeknow_tip_mobile_cn";
	
	private DBManagerImpl db = null;
	public LanguageConfigTable() {
		if (db == null) {
			db = DBManager.get();
		}
		if (!db.isTableExits(db.getConnection(), TABLE_BOTTLE_LANGUAGE_CONFIG)) {
			createBottleNetType();
		}
	}
	
	public LanguageConfigTable(Context context) {
		if (db == null) {
			db = DBManager.get(context);
		}
		if (!db.isTableExits(db.getConnection(), TABLE_BOTTLE_LANGUAGE_CONFIG)) {
			createBottleNetType();
		}
	}
	
	private void createBottleNetType() {
		String createSql = "create table if not exists "+TABLE_BOTTLE_LANGUAGE_CONFIG+" (id integer primary key autoincrement, bottle_throw_tips_en varchar, bottle_throw_tips_2_en varchar, bottle_gain_tips_en varchar," +
				"bottle_gain_tips_2_en varchar, exchange_profile_tip_en varchar, exchange_profile_tip_2_en varchar, exchange_profile_intro_en varchar, exchange_photo_tip_en varchar, exchange_photo_tip_2_en varchar,exchange_photo_intro_en varchar,without_btfriend_tip_en varchar,"+
				"without_btfriend_tip_2_en varchar,without_friend_tip_en varchar, without_friend_tip_2_en varchar,without_maybeknow_tip_en varchar,without_maybeknow_tip_invite_en varchar,without_maybeknow_tip_setup_en varchar,without_maybeknow_tip_mobile_en varchar,bottle_throw_tips_cn varchar,"+
				"bottle_throw_tips_2_cn varchar,bottle_gain_tips_cn varchar,bottle_gain_tips_2_cn varchar,exchange_profile_tip_cn varchar,exchange_profile_tip_2_cn varchar,exchange_profile_intro_cn varchar, exchange_photo_tip_cn varchar,exchange_photo_tip_2_cn vrchar, exchange_photo_intro_cn varchar,"+
				"without_btfriend_tip_cn varchar,without_btfriend_tip_2_cn varchar,"+
				"without_friend_tip_cn varchar,without_friend_tip_2_cn varchar,without_maybeknow_tip_cn varchar,without_maybeknow_tip_invite_cn varchar,without_maybeknow_tip_setup_cn varchar,without_maybeknow_tip_mobile_cn varchar)";
		db.creatTable(db.getConnection(), createSql, TABLE_BOTTLE_LANGUAGE_CONFIG);
	}
	
	public void saveBottleLanguageConfig(LanguageConfig entry) {
		try {
			ContentValues values = new ContentValues();
			values.put(bottle_throw_tips_en, entry.getBottle_throw_tips_en());
			values.put(bottle_throw_tips_2_en, entry.getBottle_throw_tips_2_en());
			values.put(bottle_gain_tips_en, entry.getBottle_gain_tips_en());
			values.put(bottle_gain_tips_2_en, entry.getBottle_gain_tips_2_en());
			values.put(exchange_profile_tip_en, entry.getExchange_profile_tip_en());
			values.put(exchange_profile_tip_2_en, entry.getExchange_profile_tip_2_en());
			values.put(exchange_profile_intro_en, entry.getExchange_profile_intro_en());
			values.put(exchange_photo_tip_en, entry.getExchange_photo_tip_en());
			values.put(exchange_photo_tip_2_en, entry.getExchange_photo_tip_2_en());
			values.put(exchange_photo_intro_en, entry.getExchange_profile_intro_en());
			values.put(without_btfriend_tip_en, entry.getWithout_btfriend_tip_en());
			values.put(without_btfriend_tip_2_en, entry.getWithout_btfriend_tip_2_en());
			values.put(without_friend_tip_en, entry.getWithout_friend_tip_en());
			values.put(without_friend_tip_2_en, entry.getWithout_friend_tip_2_en());
			values.put(without_maybeknow_tip_en, entry.getWithout_maybeknow_tip_en());
			values.put(without_maybeknow_tip_invite_en, entry.getWithout_maybeknow_tip_invite_en());
			values.put(without_maybeknow_tip_setup_en, entry.getWithout_maybeknow_tip_setup_en());
			values.put(without_maybeknow_tip_mobile_en, entry.getWithout_maybeknow_tip_mobile_en());
			values.put(bottle_throw_tips_cn, entry.getBottle_throw_tips_cn());
			values.put(bottle_throw_tips_2_cn, entry.getBottle_throw_tips_2_cn());
			values.put(bottle_gain_tips_cn, entry.getBottle_gain_tips_cn());
			values.put(bottle_gain_tips_2_cn, entry.getBottle_gain_tips_2_cn());
			values.put(exchange_profile_tip_cn, entry.getExchange_profile_tip_cn());
			values.put(exchange_profile_tip_2_cn, entry.getExchange_profile_tip_2_cn());
			values.put(exchange_profile_intro_cn, entry.getExchange_profile_intro_cn());
			values.put(exchange_photo_tip_cn, entry.getExchange_photo_tip_cn());
			values.put(exchange_photo_tip_2_cn, entry.getExchange_photo_tip_2_cn());
			values.put(exchange_photo_intro_cn, entry.getExchange_photo_intro_cn());
			values.put(without_btfriend_tip_cn, entry.getWithout_btfriend_tip_cn());
			values.put(without_btfriend_tip_2_cn, entry.getWithout_btfriend_tip_2_cn());
			values.put(without_friend_tip_cn, entry.getWithout_friend_tip_cn());
			values.put(without_friend_tip_2_cn, entry.getWithout_friend_tip_2_cn());
			values.put(without_maybeknow_tip_cn, entry.getWithout_maybeknow_tip_cn());
			values.put(without_maybeknow_tip_invite_cn, entry.getWithout_maybeknow_tip_invite_cn());
			values.put(without_maybeknow_tip_setup_cn, entry.getWithout_maybeknow_tip_setup_cn());
			values.put(without_maybeknow_tip_mobile_cn, entry.getWithout_maybeknow_tip_mobile_cn());
			
			db.save(db.getConnection(), TABLE_BOTTLE_LANGUAGE_CONFIG, values);
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			db.closeConnection();
		}

	}
	
	public LanguageConfig getBottleLanguageConfig() {
		Cursor cursor = null;
		LanguageConfig entry = null;
		try {
			cursor = db.find(db.getConnection(), "select * from " + TABLE_BOTTLE_LANGUAGE_CONFIG, null);
			if (cursor != null) {
				while (cursor.moveToNext()) {
					entry = new LanguageConfig();
					
					entry.setBottle_throw_tips_en(cursor.getString(cursor.getColumnIndex(bottle_throw_tips_en)));
					entry.setBottle_throw_tips_2_en(cursor.getString(cursor.getColumnIndex(bottle_throw_tips_2_en)));
					entry.setBottle_gain_tips_en(cursor.getString(cursor.getColumnIndex(bottle_gain_tips_en)));
					entry.setBottle_gain_tips_2_en(cursor.getString(cursor.getColumnIndex(bottle_gain_tips_2_en)));
					entry.setExchange_profile_tip_en(cursor.getString(cursor.getColumnIndex(exchange_profile_tip_en)));
					entry.setExchange_profile_tip_2_en(cursor.getString(cursor.getColumnIndex(exchange_profile_tip_2_en)));
					entry.setExchange_profile_intro_en(cursor.getString(cursor.getColumnIndex(exchange_profile_intro_en)));
					entry.setExchange_photo_tip_en(cursor.getString(cursor.getColumnIndex(exchange_photo_tip_en)));
					entry.setExchange_photo_tip_2_en(cursor.getString(cursor.getColumnIndex(exchange_photo_tip_2_en)));
					entry.setExchange_profile_intro_en(cursor.getString(cursor.getColumnIndex(exchange_photo_intro_en)));
					entry.setWithout_btfriend_tip_en(cursor.getString(cursor.getColumnIndex(without_btfriend_tip_en)));
					entry.setWithout_btfriend_tip_2_en(cursor.getString(cursor.getColumnIndex(without_btfriend_tip_2_en)));
					entry.setWithout_friend_tip_en(cursor.getString(cursor.getColumnIndex(without_friend_tip_en)));
					entry.setWithout_friend_tip_2_en(cursor.getString(cursor.getColumnIndex(without_friend_tip_2_en)));
					entry.setWithout_maybeknow_tip_en(cursor.getString(cursor.getColumnIndex(without_maybeknow_tip_en)));
					entry.setWithout_maybeknow_tip_invite_en(cursor.getString(cursor.getColumnIndex(without_maybeknow_tip_invite_en)));
					entry.setWithout_maybeknow_tip_setup_en(cursor.getString(cursor.getColumnIndex(without_maybeknow_tip_setup_en)));
					entry.setWithout_maybeknow_tip_mobile_en(cursor.getString(cursor.getColumnIndex(without_maybeknow_tip_mobile_en)));
					entry.setBottle_throw_tips_cn(cursor.getString(cursor.getColumnIndex(bottle_throw_tips_cn)));
					entry.setBottle_throw_tips_2_cn(cursor.getString(cursor.getColumnIndex(bottle_throw_tips_2_cn)));
					entry.setBottle_gain_tips_cn(cursor.getString(cursor.getColumnIndex(bottle_gain_tips_cn)));
					entry.setBottle_gain_tips_2_cn(cursor.getString(cursor.getColumnIndex(bottle_gain_tips_2_cn)));
					entry.setExchange_profile_tip_cn(cursor.getString(cursor.getColumnIndex(exchange_profile_tip_cn)));
					entry.setExchange_profile_tip_2_cn(cursor.getString(cursor.getColumnIndex(exchange_profile_tip_2_cn)));
					entry.setExchange_profile_intro_cn(cursor.getString(cursor.getColumnIndex(exchange_profile_intro_cn)));
					entry.setExchange_photo_tip_cn(cursor.getString(cursor.getColumnIndex(exchange_photo_tip_cn)));
					entry.setExchange_photo_tip_2_cn(cursor.getString(cursor.getColumnIndex(exchange_photo_tip_2_cn)));
					entry.setExchange_photo_intro_cn(cursor.getString(cursor.getColumnIndex(exchange_photo_intro_cn)));
					entry.setWithout_btfriend_tip_cn(cursor.getString(cursor.getColumnIndex(without_btfriend_tip_cn)));
					entry.setWithout_btfriend_tip_2_cn(cursor.getString(cursor.getColumnIndex(without_btfriend_tip_2_cn)));
					entry.setWithout_friend_tip_cn(cursor.getString(cursor.getColumnIndex(without_friend_tip_cn)));
					entry.setWithout_friend_tip_2_cn(cursor.getString(cursor.getColumnIndex(without_friend_tip_2_cn)));
					entry.setWithout_maybeknow_tip_cn(cursor.getString(cursor.getColumnIndex(without_maybeknow_tip_cn)));
					entry.setWithout_maybeknow_tip_invite_cn(cursor.getString(cursor.getColumnIndex(without_maybeknow_tip_invite_cn)));
					entry.setWithout_maybeknow_tip_setup_cn(cursor.getString(cursor.getColumnIndex(without_maybeknow_tip_setup_cn)));
					entry.setWithout_maybeknow_tip_mobile_cn(cursor.getString(cursor.getColumnIndex(without_maybeknow_tip_mobile_cn)));
					
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (cursor != null && !cursor.isClosed()) {
				cursor.close();
			}
		}
		return entry;
	}
	
	public void clearTable() {
		db.delete(db.getConnection(), TABLE_BOTTLE_LANGUAGE_CONFIG, null, null);
	}
}
